﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class Pass1 : PassBase
{
    public int CurrentProcessIndex = 0;

    public int CurrentQuesitionIndex = 0;

    public Transform KonwledgeParent;
    public Transform QuesitionParent;
    public Transform ProcessParent;

 


    private void Awake()
    {
        Init();

     
    }

    public override void Init()
    {
        base.Init();
        SetCurrentKonwledge(CurrentProcessIndex, KonwledgeParent);
        SetCurrentProcessLine(CurrentProcessIndex, ProcessParent);
    }

    private void SetCurrentProcessLine(int index,Transform parent)
    {
        if (index >= parent.childCount)
        {
            parent.GetChild(parent.childCount-1).GetComponent<Text>().color = Color.green;
            return;
        }

        for (int i = 0; i < parent.childCount; i++)
        {
            parent.GetChild(i).GetComponent<Text>().color = Color.white;
        }

        parent.GetChild(index).GetComponent<Text>().color = Color.green;


    }

    private void SetCurrentKonwledge(int index, Transform parent)
    {

        if (index >= parent.childCount) return;
        for (int i = 0; i < parent.childCount; i++)
        {
            parent.GetChild(i).gameObject.SetActive(false);
        }

        parent.GetChild(index).gameObject.SetActive(true);

    }



 

    public void NextKonwledge()
    {
        if (CurrentProcessIndex < ProcessParent.childCount-1)
        {
            CurrentProcessIndex++;
        }
        SetCurrentKonwledge(CurrentProcessIndex, KonwledgeParent);
        SetCurrentProcessLine(CurrentProcessIndex, ProcessParent);
    }

    public void LastKonwledge()
    {
        if ( CurrentProcessIndex>0)
        {
            CurrentProcessIndex--;
        }
        
        SetCurrentKonwledge(CurrentProcessIndex, KonwledgeParent);
        SetCurrentProcessLine(CurrentProcessIndex, ProcessParent);
    }


    public void EnterTest()
    {

        KonwledgeParent.parent.gameObject.SetActive(false);
        QuesitionParent.parent.gameObject.SetActive(true);


        AnswerSys.Instance.SetCurrentQuesition(CurrentQuesitionIndex, QuesitionParent);
        CurrentProcessIndex = ProcessParent.childCount - 1;
        SetCurrentProcessLine(CurrentProcessIndex, ProcessParent);

    }


    public void LoadScene(string sceneName)
    {
        SceneManager.LoadScene(sceneName);
    }




}
